[ES|QL] Use custom AST for suggestion, validation, etc...#166185
Merged
dej611 merged 64 commits intoelastic:feature/esql-validationfrom Oct 26, 2023
Merged
[ES|QL] Use custom AST for suggestion, validation, etc...#166185dej611 merged 64 commits intoelastic:feature/esql-validationfrom
dej611 merged 64 commits intoelastic:feature/esql-validationfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #166242
This is a PR to use an higher level AST instead of the raw ParserTree to compute all Monaco features for ES|QL.
Grammar
This PR drops the existing grammar in favour of the ES one, which a tiny tweak in order to support any case for the query.
I think we could fully adopt the ES grammar without tweaks once this issue is resolved in the antlr4ts dependency.
The adoption of the ES grammar helped also to resolve #166173 .
AST generator
The AST is a subset of the ESQL grammar parser tree, which is easier to navigate.
Tests will be provided to the tool in order to test that the tool can translate even the craziest query string.
Note that this is not preventing the query to be submitted to ES: even if a validation case fails here or the AST fails to translate part of the expression ES will always have the last word about error and warnings, which will be promptly notified to the user.
Commands coverage:
ROWROW a=1ROW a=1, b=1FROMFROM aFROM a, bFROM a [METADATA ...]FROM a, b [METADATA ...]METADATAwon't have indentifiers yetSHOWINFOFUNCTIONSEVALEVAL a = b + 1EVAL a = fnA( ... ) + fnB( ... )EVAL b + 1EVAL fnA( ... ) + fnB( ... )STATSSTATS a = fn(b) + fn(c)STATS a = fn(b) + fn(c) BY groupSTATS a = fn(b) + fn(c) BY groupA, groupBSTATS fn(b) + fn(c)STATS fn(b) + fn(c) BY groupASTATS fn(b) + fn(c) BY groupA, groupBWHERELIMITKEEPPROJECTDROPRENAME.RENAME a as bRENAMEa + 1 / 5asmyField`DISSECTGROKENRICHMV_EXPANDSORTCollect all user defined variables
eval a = ...)eval a + 1)Validation
With this new approach it would be possible to catch most of warnings and errors while typing, preventing users to submit invalid queries to ES.
Note that here the validation function can detect multiple errors and warnings at once, while ES only returns one error at the time - improving the current sub-optimal editing experience provided.
Tasks
Autocomplete
Using the same provider here to provide better contextual suggestions.
First example giving better suggestions (filtered field based on types and functions based on returned type):
Hover
Basic hover information about used functions:


Things not covered in this PR
SHOW FUNCTIONSat language bootstrapvalidatefunction an independent module?Unknown <entity> [...]messages)autocompleteon par with the current state inmainValidation cases not covered yet
... | eval var = 1 year=> ❌ it should report an error... | eval 1 + [1, 2, 3]=>-,*,/,%... | stats a = avg(field) | keep b=> ❌bshould be reported as unknown... | keep a | eval b=> ❌bshould be reported as unknown... | rename a as b, d as c, c as b=> ❌cshould be reported as unknown... | enrich policy on fieldFromEnrich=> ❌fieldFromEnrichis not reported as unknown... | eval a = round(b), b = round(a)=> ❌bshould be reported an unknownfrom ... [metadata <list of meta fields>=> ❌meta fieldswon't be validated as there's currently no available API to get themHover
Advanced usage of hover feature.
Signature
TBD